<?php
$parentCaption = BUtils::T('profile_lbl');
$caption = BUtils::T('detail_features_lbl');
$this->pageTitle = $parentCaption;

$this->breadcrumbs = array(
	$parentCaption => array('index'),
	$caption,
);

$edit_btn = BUtils::T('edit_btn');

//get url_logo
$url_logo = empty($model->url_logo) ? Yii::app()->request->baseUrl . '/img/logo_default.png' : $model->url_logo;

//define array
$aWeekDays = BUtils::WeekDayKeys(7, true);
$a24Hours = BUtils::AllHour24();
$hours_list = MerchantObject::HtmlBusinessHours($aHours, $aWeekDays, $a24Hours);

//set the subcategories with category_key
$subcategories = MerchantObject::Subcategories(Yii::app()->user->getState('category_key'));
?>
<div class="page-header position-relative">
	<h1>
		<?php echo $parentCaption; ?>
		<small>
			<i class="icon-double-angle-right"></i>
			<?php echo $caption; ?>
		</small>
	</h1>
</div><!--/.page-header-->

<div class="row-fluid">
	<div class="space-6"></div>
	
	<div class="row-fluid">
		<div class="span12">
			<div class="widget-box transparent">
				<div class="widget-header">
					<h4 class="lighter">
						<i class="icon-edit blue"></i> <?php echo $caption; ?>
					</h4>
				</div>
				<div class="widget-body">
					<div class="widget-main">
<div class="biz-form">
<?php echo CHtml::form(Yii::app()->createUrl('/profile/saveTags'), 'post', array('id'=>'merchant-tag-form')); ?>
				<div class="fieldswrap">
<?php if (count($subcategories) > 0) { ?>
<div class="fields">
	<div class="tag-label" id="cuisine_type_lbl"><?php echo BUtils::T('cuisine_type_lbl'); ?></div>
	<div class="tag-list">
		<?php echo CHtml::checkBoxList('cuisine_type', explode(',', $tag['cuisine_type']), $subcategories, array(
			'class'=>'',
			'separator'=>'',
			'template'=>'<span class="fixed-list" style="width:200px;">{input} {label}</span>'
		)); ?>
	</div>
</div>
<?php } ?>
<div class="fields">
	<div class="tag-label"><?php echo BUtils::T('payment_options_lbl'); ?></div>
	<div class="tag-list">
		<?php echo CHtml::checkBoxList('payment_options', explode(',', $tag['payment_options']), BTag::PaymentOptions(), array(
			'class'=>'',
			'separator'=>'',
			'template'=>'<span class="fixed-list">{input} {label}</span>'
		)); ?>
	</div>
</div>
<div class="fields">
	<div class="tag-label"><?php echo BUtils::T('service_languages_lbl'); ?></div>
	<div class="tag-list">
		<?php echo CHtml::checkBoxList('service_languages', explode(',', $tag['service_languages']), BTag::ServiceLanguages(), array(
			'class'=>'',
			'separator'=>'',
			'template'=>'<span class="fixed-list">{input} {label}</span>'
		)); ?>
	</div>
</div>
<div class="fields">
	<div class="tag-label">
		<?php echo BUtils::T('car_parking_lbl'); ?>
	</div>
	<div class="tag-list">
		<?php echo CHtml::checkBoxList('car_parking', explode(',', $tag['car_parking']), BTag::CarParking(), array(
			'separator'=>'',
			'template'=>'<span class="nature-list">{input} {label}</span>'
		)); ?>
	</div>
</div>
				</div><!-- end of .fieldswrap -->
				<div class="margin actions">
					<?php echo CHtml::ajaxSubmitButton(BUtils::T('detail_features_save_btn'), Yii::app()->createUrl('profile/saveTags'), array(
						'dataType' => 'json',
						'beforeSend' => 'js:function(){beforeSubmit("#tags-button");}',
						'success' => 'js:function(data){afterSubmit(data, "#tags-button");}'
					), array('class' => 'button button-confirm button-huge', 'id'=>'tags-button')); ?>
					<?php echo CHtml::button(BUtils::T('cancel_btn'), array('class'=>'button button-huge button-thin', 'onclick'=>'history.go(-1);', 'confirm'=>BUtils::T('cancel_btn_msg'))); ?>
				</div>
<?php echo CHtml::endForm(); ?>
</div>
					</div>
				</div>
			</div>
		</div><!-- end left side -->
		
		<div class="span5" style="display:none;">
			<div class="widget-box transparent">
				<div class="widget-header">
					<h4 class="lighter smaller">
						<i class="icon-eye-open blue"></i> Preview
					</h4>
				</div>
				<div class="widget-body">
					<div class="widget-main">
<div class="biz-form" style="position:relative;">
				<h3><?php echo $model->name; ?></h3>
				<div style="position:absolute; right:15px; top:15px;">
					<a class="button button-small button-confirm" href="<?php echo Yii::app()->createUrl('/profile/form'); ?>"><span><?php echo $edit_btn; ?></span></a>
				</div>
				<div class="fieldswrap">
					<div class="fields row-fluid">
						<div class="span5">
							<img class="img-polaroid" src="<?php echo $url_logo; ?>" alg="" />
						</div>
						<div class="span7">
							<div class="address"><?php echo $model->address . '<br />' . $model->postcode . ' ' . $model->city; ?></div>
							<div class="phone"><?php echo $model->phone; ?></div>
							<div class="link"><?php echo $model->url_site; ?></div>
							<?php if ($model->average_price > 0) { ?>
							<div class="average"><?php echo BUtils::T('average_price_lbl') . ': ' . Yii::app()->locale->numberFormatter->formatCurrency($model->average_price, 'EUR'); ?></div>
							<?php } ?>
						</div>
						<div class="clear"></div>
					</div>
				</div>
				<div class="fieldswrap">
					<div class="fields">
						<div class="fixed-title"><?php echo BUtils::T('opening_hours_lbl'); ?></div>
						<div class="added-hours">
							<?php echo $hours_list; ?>
						</div>
					</div>
				</div>
				<div class="fieldswrap">
					<div class="fields">
						<div class="fixed-title"><?php echo BUtils::T('detail_features_lbl'); ?></div>
						<div class="tags">
							<?php echo MerchantObject::HtmlDetailFeatures($tag); ?>
						</div>
					</div>
				</div>
<?php if (!empty($model->brief)) { ?>
				<div class="fieldswrap">
					<div class="fields mobile">
						<div class="fixed-title"><?php echo BUtils::T('merchant_brief_lbl'); ?></div>
						<div class="opening">
							<p><?php echo nl2br($model->brief); ?></p>
						</div>
					</div>
				</div>
<?php } ?>
</div>
					</div>
				</div>
			</div>
		</div><!-- end right side -->
	</div>
</div>

<script type="text/javascript">
$(function() {
	//only select one item
	$("#alcohol_license :checkbox").click(function(){
		var checked = $(this).attr("checked");
		$("#alcohol_license input:checked").removeAttr("checked");
		if (checked) { $(this).attr("checked","checked"); }
	});
});
function beforeSubmit(eId) {
	$(eId).attr('disabled','disabled').addClass('button-disabled');
}
function afterSubmit(data, eId) {
	$(eId).removeAttr('disabled').removeClass('button-disabled');
	if (data.success) {
		alert(data.success);
		location.reload();
	} else {
		for (var ele in data) {
			$('#'+ele).focus();
			return;
		}
	}
}
</script>

